#
#		Author: Alexandros Sigalas
#
#      This program is free software; you can redistribute it and/or modify
#      it under the terms of the GNU General Public License as published by
#      the Free Software Foundation; either version 2 of the License, or
#      (at your option) any later version.
#      
#      This program is distributed in the hope that it will be useful,
#      but WITHOUT ANY WARRANTY; without even the implied warranty of
#      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#      GNU General Public License for more details.
#      
#      You should have received a copy of the GNU General Public License
#      along with this program; if not, write to the Free Software
#      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#      MA 02110-1301, USA.

from _core import Material, Vector

### Color Utils
def col2RGB(color):
    '''Convert rgb color from float(0.0-1.0) to integer(0-255)'''
    return  [int(c * 255) for c in color]

def indexColorFromRGB(rgb, color_map):
    '''Find closest possible indexed color number for an rgb color
    
    Parameters:
        rgb: tuple or list of 3 floats or 3 integers 
        color_map: dictionary of colors in (index: [r,g,b]) form
    
    Returns:
        key of closest color in dict
    
    NOTE: rgbcolor and color_map must be of the same notation. 
    (integer(0-255) notation or float(0.0-1.0) notation)
    '''
    tmp= Vector(rgb)
    dists = [((tmp - color).length, key) for key, color in color_map.iteritems()]
    return min(dists)[1]

default_lineweight= 0.2
default_fill_color= [1.0,1.0,1.0]
default_line_color= [0.0,0.0,0.0]

default_material= Material("default")
default_section= Material("default-section")
default_hidden= Material("default-hidden")


